import { _decorator, Component, EventTouch, Prefab,Node, instantiate, Vec3 } from "cc";
const { ccclass, property } = _decorator;

@ccclass("PlayerControl")
export class PlayerControl extends Component {
    @property(Prefab)
    bullet: Prefab = null;

    start() {
        //添加触摸监听，实现飞机移动
        this.node.on(Node.EventType.TOUCH_MOVE,
            (e: EventTouch) => {
                const { x, y } = e.getUILocation();
                this.node.setWorldPosition(new Vec3(x, y))
            })

        //添加定时器，实现
        this.schedule(() => {
            const { x, y } = this.node.getPosition();
            const node = instantiate(this.bullet);
            node.setParent(this.node.parent);
            node.setPosition(x, y + 70);
        }, 0.2);
    }

    update(deltaTime: number) { }
}
